
<template>
  <div class="yy-whp-store-list">
    <!--列表-->
    <div class="yy-store-list-list" v-show="type=='list'">
      <Card>
        <p slot="title">
          <Icon type="md-list" />
          库存清单列表
        </p>
        <Form ref="formInline" :model="searchForm"  inline>
          <FormItem prop="user">
            <Input type="text" v-model="searchForm.itemNum" placeholder="物品编码"></Input>
          </FormItem>
          <FormItem prop="user">
            <Input type="text" v-model="searchForm.itemName" placeholder="物品名称"></Input>
          </FormItem>
          <FormItem prop="user">
            <Select class="select" v-model="searchForm.storageNum" @on-change="changeStorage(searchForm.storageNum)" placeholder="请选择仓库">
              <Option value="0">请选择</Option>
							<Option v-for="(dataSt,index) in dataStorage" :value="dataSt.storageNum" :key="index">{{dataSt.storageName}}</Option>
            </Select>
          </FormItem>
          <FormItem prop="user">
            <Select class="select" v-model="searchForm.localNum" placeholder="请选择库区">
              <Option value="0" >请选择</Option>
							<Option v-for="(dataLt,index) in dataLoctions" :value="dataLt.localNum" :key="index">{{dataLt.localName}}</Option>	
            </Select>
          </FormItem>
           <FormItem prop="user">
            <Select class="select" v-model="searchForm.hasNum" placeholder="请选择库存状态">
              <Option value="0">全部</Option>
              <Option value="1">大于0</Option>
              <Option value="2">正常</Option>
              <Option value="3">低于预警</Option>
              <Option value="4">高于预警</Option>
            </Select>
          </FormItem>
          <FormItem>
            <Button type="primary" @click="handleSearch()">查询</Button>
          </FormItem>
        </Form>
        <Table :columns="columns" :data="data" ></Table>
        <div style="margin: 10px;overflow: hidden">
          <div style="float: right;">
            <Page :total="page.total" :page-size="page.pageSize" :current="1" @on-change="changePage" show-total></Page>
          </div>
        </div>
      </Card>
    </div>
    <!--详情-->
    <div class="yy-store-list-details" v-show="type=='details'">
       <Card>
        <p slot="title">
          <Icon type="md-paper"/>
          查看详情
        </p>
        <p slot="extra">
          <Button type="primary" @click="goBack()">返回</Button>
        </p>
        <div class="details" :data="detailsList">
          <p class="details-title"><span>类别:</span>{{currentData.cateName}}</p>
          <p class="details-title"><span>物品编号:</span>{{currentData.itemNum}}</p>
          <p class="details-title"><span>物品名称:</span>{{currentData.itemName}}</p>
          <p class="details-title"><span>品牌:</span>{{currentData.brand}}</p>
          <p class="details-title"><span>规格:</span>{{currentData.size}}</p>
					<p class="details-title"><span>物品序列号:</span>{{currentData.sn}}</p>
					<p class="details-title"><span>是否耐用:</span>{{currentData.isSpare}}</p>
					<p class="details-title"><span>仓库:</span>{{currentData.storageName}}</p>
					<p class="details-title"><span>库区:</span>{{currentData.localName}}</p>
					<p class="details-title"><span>库存数量:</span>{{currentData.num}}</p>
					<p class="details-title"><span>单价:</span>{{currentData.unitPrice}}</p>
					<p class="details-title"><span>金额:</span>{{currentData.amount}}</p>
					<p class="details-title"><span>品质:</span>{{currentData.batchNum}}</p>
					<p class="details-title"><span>预警下限:</span>{{currentData.minNum}}</p>
					<p class="details-title"><span>预警上限:</span>{{currentData.maxNum}}</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import API from "./api";
import ValidatorRule from "@/filters/validator-rule";
import { formatNetTime } from "@/libs/tools";
import i18n from "./locale";
import wareHouseMixin from "../common/warehouse-mixin";

export default {
  name: "yy-whp-store-list",
  mixins: [wareHouseMixin],
  data() {
    return {
      i18n: i18n,
      currentData: "",
      detailsModal: false,
      type: "list",
      page: {
        total: 0,
        pageSize: 20
      },
      searchForm: {
        itemNum: "",
        itemName: "",
        userID: "",
        userName: "",
        b_UserRole: "",
        storageNum: "",
        localNum: "",
        hasNum: "",
        isShowAllSpareItem: 1
      },
      editFormInLine: {
        supplierNum: "",
        supplierName: "",
        contact: "",
        tel: "",
        remark: ""
      },

      editFormRuleInline: {
        supplierNum: ValidatorRule.require,
        supplierName: ValidatorRule.require,
        tel: ValidatorRule.tel
      },

      columns: [
        {
          title: "类别",
          key: "cateName"
        },
        {
          title: "物品编号",
          key: "itemNum"
        },
        {
          title: "物品名称 ",
          key: "itemName"
        },
        {
          title: "品牌 ",
          key: "brand"
        },
        {
          title: "规格 ",
          key: "size"
        },
        {
          title: "物品序列号 ",
          key: "sn"
        },
        {
          title: "是否耐用 ",
          key: "isSpare",
          render: (h, params) => {
            return h("span", params.row.isSpare == 0 ? "否" : "是");
          }
        },
        {
          title: "仓库 ",
          key: "storageName"
        },
        {
          title: "库区 ",
          key: "localName"
        },
        {
          title: "库存数量 ",
          key: "num"
        },
        {
          title: "单价 ",
          key: "unitPrice"
        },
        {
          title: "金额 ",
          key: "amount"
        },
        {
          title: "品质 ",
          key: "batchNum"
        },
        {
          title: "预警下限 ",
          key: "minNum"
        },
        {
          title: "预警上限 ",
          key: "maxNum"
        },
        {
          title: "操作",
          key: "action",
          width: 180,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.details(params.index);
                    }
                  }
                },
                "查看"
              )
            ]);
          }
        }
      ],
      data: [],
      detailsList: []
    };
  },

  mounted() {
    this.handleSearch();
  },

  computed: {},

  methods: {
    handleSearch() {
      let obj = this.searchForm;
      obj.pageNum = 1;
      obj.pageSize = this.page.pageSize;
      this.searchForm = obj;
      this.getList(obj);
    },

    getList(obj) {
      API.getList(obj)
        .then(res => {
          if (res.code == 200) {
            let data = res.data;
            this.page.total = data.total;
            this.page.pageSize = data.pageSize;
            this.data = data.list;
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
        });
    },

    changePage(pageNum) {
      let obj = this.searchForm,
        maxPageNum = Math.ceil(this.page.total / this.page.pageSize);
      if (obj.pageNum > maxPageNum) {
        obj.pageNum = maxPageNum;
      } else {
        obj.pageNum = pageNum;
      }
      this.searchForm = obj;
      this.getList(obj);
    },

    goBack() {
      this.type = "list";
    },

    details(index) {
      this.type = "details";
      this.currentData = _.clone(this.data[index]);
      let obj = {
        userID: "chenweihan",
        userName: "陈维汉",
        b_UserRole: "admin"
      };
      API.details(obj)
        .then(res => {
          if (res.code == 200) {
            let dataDet = res.data;
            this.detailsList = dataDet.list;
          }
        })
        .catch(err => {
          this.$Message.error("请求异常！");
        });
      if (this.currentData.isSpare == 0) {
        this.currentData.isSpare = "否";
      } else {
        this.currentData.isSpare = "是";
      }
    }
  }
};
</script>
<style lang="less" >
@import "./yy-whp-store-list.less";
</style>
